﻿$(function () {
    FielCostesInfo();
})
var Id = location.search.substring(2).split("=")[1];
console.log(Id);
function FielCostesInfo() {
    $.get("http://10.31.60.18:8000/AuthorizationGetRout/api/DepartmentShow/ArchivesReadById?departId=" + Id, function (res) {
        console.log(res);
        $("#departCode").val(res.departCode);
        $("#departName").val(res.departName);
        $("#parentId").val(res.parentId);
        $("#departtype").val(res.departtype);
        $("#departArea").val(res.departArea);
        layui.use(['form'], function () {
            var form = layui.form;
            $("[name='parentId'][value='" + res.parentId + "']").prop("checked", "checked");
            form.render();
        });
    })
}
//配置插件目录
layui.config({
    base: '/mods/'
});
layui.use(['form', 'laydate', 'util', 'layarea'], function () {
    var obj = {};
    var form = layui.form;
    var layer = layui.layer;
    var laydate = layui.laydate;
    var util = layui.util;
    var layarea = layui.layarea;

    // 提交事件
    form.on('submit(demo1)', function (data) {
        var field = data.field;
        obj.departId = Id;
        obj.departCode = field.departCode;
        obj.departName = field.departName;
        obj.departtype = field.departtype;
        obj.departArea = field.departArea;
        obj.parentId = field.parentId;

        $.ajax({
            type: "put",
            url: "http://10.31.60.18:8000/AuthorizationSetRout/api/Department/UnitsUpd",
            data: JSON.stringify(obj),
            contentType: "application/json",
            success: res => {
                if (res > 0) {
                    var icon = 0;
                    layer.alert('修改成功', {
                        icon: 1,
                        shadeClose: true,
                        title: "部门修改",
                    }, function () {
                        location.href = "/Department/DepartmentList";
                    });
                } else {
                    alert("修改失败");
                }
            }
        })
        return false; // 阻止默认 form 跳转
    });
});